;--------------------------------------
;
; remvw.asm 
;
; 1) restore previously saved screen 
;    image
;

;--------------------------------------
;
; include all defines, macros, 
; prototypes and set up memory model
;

include tab6.inc

;--------------------------------------
;
; Declare Code segment
;

        .CODE

;--------------------------------------
;
; removeWind (WINDOW *wptr)
;

removeWind PROC PASCAL USES ES DI DS BX,wptr:Ptr Window
        LOCAL   amount:Word
        LOCAL   ur:Byte,uc:Byte,lr:Byte,lc:Byte
        LOCAL   attr:Byte
        LOCAL   c_ctr:Byte,r_ctr:Byte
        LOCAL   chr:Byte
;
; relocate Window structure data to locals
   IF mdl eq 1
        mov     bx,wptr
   ELSE
        lds     bx,wptr
   ENDIF
        mov     al,(WINDOW Ptr [bx]).ur ; relocate upper row
        mov     ur,al
        mov     al,(WINDOW Ptr [bx]).uc ; relocate upper col
        mov     uc,al
        mov     al,(WINDOW Ptr [bx]).lr ; relocate lower row
        mov     lr,al
        mov     al,(WINDOW Ptr [bx]).lc ; relocate lower column
        mov     lc,al
        mov     al,(WINDOW Ptr [bx]).lc ; relocate lower column
        mov     lc,al
;
; restore the underneath screen image
        mov     ax,(WINDOW Ptr [bx]).s_img ; 
        mov     es,ax                     ;
        xor     di,di                     ;
        mov     al,ur                     ; set row start
        mov     r_ctr,al                  ; variable
        .REPEAT                           ; save by row loop
        mov     al,uc                     ; set column start
        mov     c_ctr,al                  ; variable
        .REPEAT                           ; save byt column loop

        mov     ax,Word Ptr es:[di]
        inc     di
        inc     di
        mov     chr,al
        mov     attr,ah
        INVOKE  vdChar,r_ctr,c_ctr,chr,attr  ; write screen char & attr

        mov     al,c_ctr                  ; xfer to al for UNTIL
        inc     c_ctr                     ; increment column counter
        .UNTIL (al == lc )              ; column loop done?

        inc     r_ctr                     ; increment row counter
        mov     al,r_ctr                  ; xfer to al for UNTIL
        .UNTIL (al > lr)               ; repeat until last row saved

        ret
removeWind ENDP

;
; End of source file

        END

;
;--------------------------------------
 
